window.addEventListener('load', function () {
    var body = document.querySelector('body');
    var item = document.querySelector('.item');
    var del = document.querySelectorAll('.del');
    var mask = document.querySelector('.mask');
    var sure = document.querySelector('.sure');
    var want = document.querySelector('.want');
    var refuse = document.querySelector('.refuse');
    var flag = 0;
    // var y=body.offsetHeight;
    // console.log(y);
    // mask.style.length="y+'px'";
    var Cx = sure.clientX;
    var Cy = sure.clientY;
    item.addEventListener('mouseenter', function () {
        this.style.overflow = 'auto';
    })
    item.addEventListener('mouseleave', function () {
        this.style.overflow = 'hidden';
    })
    for (var i = 0; i < del.length; i++) {
        del[i].addEventListener('click', function () {
             sure.style.left='33%';
             sure.style.top='50%';
             if(flag==1){
                 item.removeChild(this.parentNode);
                 flag=0;
                 getSum1()
                 return;
            }
            console.log(flag);
            mask.style.display = 'block';
            sure.addEventListener('mousedown', function (e) {
                var x = e.pageX - sure.offsetLeft;
                var y = e.pageY - sure.offsetTop;
                document.addEventListener('mousemove', move)
                function move(e) {
                    sure.style.left = e.pageX - x + 'px';
                    sure.style.top = e.pageY - y + 'px';
                }
                document.addEventListener('mouseup', function () {
                    document.removeEventListener('mousemove', move);
                })
            })
        })
        want.addEventListener('click', function () {
            mask.style.display = 'none';
            flag=0;
        })
        refuse.addEventListener('click', function () {
              mask.style.display = 'none';
             flag = 1;
         })
    }
    function getSum1(){
        var count=0;
        var money=0;
        var sum=document.querySelectorAll('.sum');
        var sl=document.querySelectorAll('.sl');
        var add1=document.querySelector('.add1');
        var add2=document.querySelector('.add2');
        var empty=document.querySelector('.empty');
        for(var i=0;i<sum.length;i++){
            p=sum[i].innerHTML.substr(1);
            console.log(parseFloat(p));
            money += parseFloat(p);
        }
        console.log(money);
        add2.innerHTML=money.toFixed(2);
        for(var i=0;i<sl.length;i++){
            s=parseInt(sl[i].value);
            console.log(s);
            count += parseInt(s);
        }
        console.log(count);
        add1.innerText=count;
        if(count==0){
            empty.style.display='block';
        }
    }
})